package com.bjpowernode.crm.workbench.service.serviceimpl;

import com.bjpowernode.crm.workbench.dao.RemarkDao;
import com.bjpowernode.crm.workbench.eneity.Activity;
import com.bjpowernode.crm.workbench.eneity.ActivityRemark;
import com.bjpowernode.crm.workbench.exception.ActivityException;
import com.bjpowernode.crm.workbench.service.ActivityRemarkService;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public class ActivityRemarkServiceImpl implements ActivityRemarkService {
    private RemarkDao remarkDao;

    public void setRemarkDao(RemarkDao remarkDao) {
        this.remarkDao = remarkDao;
    }

    @Override
    @Transactional
    public List<ActivityRemark> queryRemarks(String activityId) {
        //调用dao进行查询
        List<ActivityRemark> remarkList=remarkDao.queryRemarks(activityId);
        return remarkList;
    }

    @Override
    @Transactional
    public Boolean insertRemark(ActivityRemark remark) throws ActivityException {
        Boolean flag=true;
        //调用dao
        int result=remarkDao.insertRemark(remark);
        //判断结果
        if (result!=1){
            flag=false;
            throw new ActivityException("备注信息添加失败");
        }
        return flag;
    }

    @Override
    @Transactional
    public Boolean remove(String id) throws ActivityException {
        Boolean flag=null;
        //调用dao
        int result=remarkDao.remove(id);
        if (result!=1){
            flag=false;
            throw new ActivityException("备注信息添加失败");
        }else {
            flag=true;
        }
        return flag;
    }

    @Override
    @Transactional
    public Boolean update(ActivityRemark remark) throws ActivityException {
        Boolean flag=true;
        //调用dao
        int result=remarkDao.update(remark);
        if (result!=1){
            flag=false;
            throw new ActivityException("备注信息修改失败");
        }
        return flag;
    }
}
